package javaDemo08.员工表处理;


public class Employee implements Comparable {
    /**
     * 成员变量
     */
    private String workid;
    private String name;
    private String gender;
    private String date;
    private String grade;
    private int wages;

    /**
     * 构造器
     *
     * @param workid
     * @param name
     * @param gender
     * @param date
     * @param grade
     * @param wages
     */
    public Employee(String workid, String name, String gender, String date, String grade, String wages) {
        this.workid = workid;
        this.name = name;
        this.gender = gender;
        this.date = date;
        this.grade = grade;
        this.wages = Integer.parseInt(wages);

    }

    /**
     * get set 方法
     *
     * @return
     */

    public String getWorkid() {
        return workid;
    }

    public void setWorkid(String workid) {
        this.workid = workid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getData() {
        return date;
    }

    public void setData(String date) {
        this.date = date;
    }

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    public int getWages() {
        return wages;
    }

    public void setWages(int wages) {
        this.wages = wages;
    }

    /**
     * 对象输出
     *
     * @return
     */
    @Override
    public String toString() {
        return workid + "\t" + name + "\t" + gender + "\t" + date + "\t" + grade + "\t" + wages;
    }

    /**
     * 继承比较器
     *
     * @param o the object to be compared.
     * @return int
     */
    @Override
    public int compareTo(Object o) {
        if (o instanceof Employee) {
            Employee e = (Employee) o;
            return compareGrade(e);
        } else {
            throw new RuntimeException("传入类型不一致");
        }
    }

    /**
     * 比较方法
     *
     * @param o
     * @return int
     */
    private int compareGrade(Employee o) {
        String[] list = this.grade.split("P");
        int a = Integer.parseInt(list[1]);
        String[] list2 = o.getGrade().split("P");
        int b = Integer.parseInt(list2[1]);
        if (a > b) {
            return 1;
        } else if (a == b) {
            return compareWages(o);
        } else {
            return -1;
        }
    }

    private int compareWages(Employee o) {
        if (this.wages > o.getWages()) {
            return 1;
        } else if (this.wages == o.getWages()) {
            return compareWorkid(o);
        } else {
            return -1;
        }
    }

    private int compareWorkid(Employee o) {
        int a = Integer.parseInt(this.workid);
        int b = Integer.parseInt(o.getWorkid());
        if (a > b) {
            return 1;
        } else if (a == b) {
            return 0;
        } else {
            return -1;
        }
    }
}
